#include <iostream>
#include <map>
#include <vector>
using namespace std;

class Worker
{
public:
    Worker(string name, int salery) : m_Name(name), m_salery(salery)
    {
    }

    void print()
    {
        cout << "name" << m_Name << " salery:" << m_salery << endl;
    }
    string m_Name;
    int m_salery;
};

void createWorker(vector<Worker> &workerVector)
{
    workerVector.push_back(Worker("A", rand()));
    workerVector.push_back(Worker("B", rand()));
    workerVector.push_back(Worker("C", rand()));
    workerVector.push_back(Worker("D", rand()));
    workerVector.push_back(Worker("E", rand()));
    workerVector.push_back(Worker("F", rand()));
    workerVector.push_back(Worker("G", rand()));
    workerVector.push_back(Worker("H", rand()));
    // workerVector.push_back(Worker("",rand()));
}

void makeGroup(vector<Worker> &v, multimap<int, Worker> &m)
{
    for (vector<Worker>::iterator it = v.begin(); it != v.end(); ++it)
    {
        int departId = rand()%3;
        m.insert(make_pair(departId, *it));
    }
}

void showByGroup(multimap<int, Worker> &m)
{
    for(int j=0;j<3;++j){
    multimap<int, Worker>::iterator pos = m.find(j);
    int num = m.count(j);
    cout << 0 <<num<< endl;
    for (int i = 0; i < num; ++i, ++pos)
    {
        pos->second.print();
    }
    }
}

int main()
{
    srand(time(NULL));
    vector<Worker> v1;
    multimap<int, Worker> m1;
    createWorker(v1);
    for (vector<Worker>::iterator it = v1.begin(); it != v1.end(); ++it)
    {
        it->print();
    }
    makeGroup(v1,m1);
    showByGroup(m1);

    return 0;
}